package com.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class IndexController {
	private Logger logger = LoggerFactory.getLogger(getClass());
	/*****
	 * 测试全局异常
	 * @return
	 */
	@RequestMapping("/zero")
	public String zero() {
		int i= 1/0;
		return "Hello World";
	}	
	
	/****
	 * http://localhost:8080/index
	 * 测试Freemarker
	 * @param map
	 * @return
	 */
	@RequestMapping("/index")
	public String index(Map<String, Object> map) {
	    map.put("name","美丽的天使...");
		return "index";
	}
	
	
	/****
	 * http://localhost:8080/freemarker
	 * freemarker其他用法
	 * @param map
	 * @return
	 */
	@RequestMapping("/freemarker")
	public String freemarker(Map<String, Object> map) {
	    map.put("name","###蚂蚁课堂###");
	    map.put("sex",1);
	    List<String> userlist=new ArrayList<String>();
	    userlist.add("余胜军");
	    userlist.add("张三");
	    userlist.add("李四");
	    map.put("userlist",userlist);
	    return "freemarker";
	}
	
	/****
	 * aop测试
	 * @param name
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@ResponseBody
	@RequestMapping("/aop")
	public Map aop(String name) {
		Map map =new HashMap();
		map.put("name", name);
	    return map;
	}
	
	@Value("${name}")
	private String name;
   
	/****
	 * 测试通过配置文件得到key和value
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getValue")
	public String getValue() {
		return name;
	}
	  
   
	
 
}
